package com.qianbao.controller.v1.step;


import com.qianbao.components.excepion.CommonException;
import com.qianbao.components.svresut.Result;
import com.qianbao.components.svversion.ApiVersion;
import com.qianbao.domain.step.StepEntity;
import com.qianbao.service.step.RunStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.HashMap;

@Controller
@ApiVersion(1)
@RequestMapping("/stepcenter/{version}/")
public class RunStepController {

    @Autowired
    private RunStepService service;



    @RequestMapping("/step-change-to-coin")
    @ResponseBody
    public Result stepChangeToCoin(@Valid StepEntity entity){
        try {
            // 这个是转换了多少金币
            int coin = service.stepChangeToCoin(entity);
            HashMap<String, String> map = new HashMap<>();
            map.put("coin",String.valueOf(coin));
            return Result.success(map);
        } catch (CommonException e) {
            e.printStackTrace();
            return Result.fail(e.getCode(),e.getMessage());
        }
    }


    @RequestMapping("/can-change-coin")
    @ResponseBody
    public Result findCanChangeCoin(@Valid StepEntity entity){
        try {
            // 这个是有多少金币可以转换
            int coin = service.findCanChangeCoin(entity);
            HashMap<String, String> map = new HashMap<>();
            map.put("coin",String.valueOf(coin));
            return Result.success(map);
        } catch (CommonException e) {
            e.printStackTrace();
            return Result.fail(e.getCode(),e.getMessage());
        }
    }



}
